from ui import ImageProcessorUI
from .base import ImageProcessor
from PIL import Image, ImageEnhance

class BrightnessContrastProcessor(ImageProcessor):
    def process(self, image: Image.Image, **kwargs) -> Image.Image:
        """
        调整图像的亮度和对比度。
        参数:
        - image: Image.Image，输入图像。
        - **kwargs: 必须包含 'brightness_factor' 和 'contrast_factor'。
        返回:
        - Image.Image，调整后的图像。
        """
        brightness_factor = kwargs.get('brightness_factor', 1.0)
        contrast_factor = kwargs.get('contrast_factor', 1.0)
        enhancer = ImageEnhance.Brightness(image)
        image = enhancer.enhance(brightness_factor)
        enhancer = ImageEnhance.Contrast(image)
        image = enhancer.enhance(contrast_factor)
        return image

    def get_ui_parameters(self, ui: "ImageProcessorUI") -> dict:
        return {
            'brightness_factor': ui.brightness_scale.get(),
            'contrast_factor': ui.contrast_scale.get()
        }